package com.rongshu.view.penpal.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.rongshu.R;
import com.rongshu.view.base.AdapterListener;
import com.rongshu.view.home.bean.LabelResponse;

import java.util.List;

/**
 * created by zhengweis on 2018/11/9.
 * description：
 */
public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.ViewHolder> {
    private Context context;
    private List<LabelResponse.ResponseBean> list;
    private AdapterListener listener;

    public LabelsAdapter(Context context, List<LabelResponse.ResponseBean> list) {
        this.context = context;
        this.list = list;
    }

    public void setAdapterLitener(AdapterListener listener) {
        this.listener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_penpal_edit_label, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.content.setText(list.get(position).getTitle());
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.callBack(list.get(position));
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView content;
        private RelativeLayout delete;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            content = itemView.findViewById(R.id.content);
            delete = itemView.findViewById(R.id.delete);
        }
    }
}
